package com.naxiangfish.cn.splash;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.naxiangfish.cn.R;
import com.naxiangfish.cn.naxiangfish.MainActivity;
import com.naxiangfish.cn.utils.ToastMake;
import com.naxiangfish.cn.weigit.NaXiangProgressView;
import com.naxiangfish.cn.weigit.NaXiangVideoView;
import com.naxiangfish.cn.weigit.NoScrollViewPager;
import com.naxiangfish.cn.weigit.OnFinishListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 作者: 赵航
 * 创建时间: 2018/8/11 15:23
 * 描述:
 */
public class SplashActivity extends AppCompatActivity implements SplashView {
    @BindView(R.id.naxiangvideo)
    NaXiangVideoView    mVideoView;
    @BindView(R.id.splashprogressview)
    NaXiangProgressView splashprogressview;
    @BindView(R.id.splashtext)
    TextView            splashtext;
    @BindView(R.id.splashjemp)
    RelativeLayout      splashjemp;
    @BindView(R.id.splashpager)
    NoScrollViewPager   splashpager;
    @BindView(R.id.splashjeempimage)
    ImageView           splashjeempimage;

    private Unbinder mUnbinder;

    private List<String> mUri = new ArrayList<>();
    private SplashImpView mImpView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        mUnbinder = ButterKnife.bind(this);
        //滑动图片加载接口

        mImpView = new SplashActivityImp(this);

        //播放视频
        //        mImpView.setItViodView(splashtext, mVideoView, splashprogressview);
        if (mUri.size() != 0) {
            mUri.clear();
        }
        mUri.add("http://jzvd-pic.nathen.cn/jzvd-pic/00b026e7-b830-4994-bc87-38f4033806a6.jpg");
        mUri.add("http://jzvd-pic.nathen.cn/jzvd-pic/1d935cc5-a1e7-4779-bdfa-20fd7a60724c.jpg");
        mUri.add("http://jzvd-pic.nathen.cn/jzvd-pic/a019ffc1-556c-4a85-b70c-b1b49811d577.jpg");
        mUri.add("http://wx2.sinaimg.cn/mw690/006ZrXHXgy1fsr074hxtyg308w07xu0x.gif");
        mUri.add("http://jzvd-pic.nathen.cn/jzvd-pic/f03cee95-9b78-4dd5-986f-d162c06c385c.png");

        //滑动图片切换界面
        splashpager.setNoScroll(true);
        mImpView.initMovePicture(splashpager, mUri, splashjeempimage);
        splashjeempimage.setVisibility(View.INVISIBLE);
        splashpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
                if (i == mUri.size() - 1) {
                    splashjeempimage.setVisibility(View.VISIBLE);
                } else {
                    splashjeempimage.setVisibility(View.INVISIBLE);
                }
            }

            @Override
            public void onPageSelected(int i) {


            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });


        splashjeempimage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
                finish();
            }
        });

    }

    @OnClick(R.id.splashjemp)
    public void onViewClicked() {
        startActivity(new Intent(SplashActivity.this, MainActivity.class));
        finish();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mVideoView != null) {
            mVideoView.stopPlayback();
            mVideoView = null;
        }
        mUnbinder.unbind();
    }


    //跳到主界面
    @Override
    public void jmpToMainActivity() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
                SplashActivity.this.finish();
            }
        });

    }

    //点击滑动屏幕
    @Override
    public void pressPager(int which, ImageView imageView) {

        ToastMake.showToast("这是第"+which+"张图片");

        System.out.println("这是第"+which+"张图片");
    }
}